home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / geom / knownclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  3.2 KB  |  139 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. /*
  13.  * $Header: /usrb/gcg/ngrap/src/lib/gprim/geom/RCS/knownclass.c,v 1.20 1993/08/31 18:09:08 slevy Exp $
  14.  */
  15.  
  16. #include <string.h>
  17.  
  18. #include "geomclass.h"
  19.  
  20. /*
  21.  * Here's we list all classes known to this object library.
  22.  * Edit this if you add a new class for general use.
  23.  * It's not mandatory to list a class here, but it helps -- generic
  24.  * GeomLoad, GeomPrivate, GeomClassForAll routines benefit from this.
  25.  *
  26.  * Some may not really be linked in, but only ghosts from the stub library.
  27.  * We tell ghosts from warm bodies by their "present" tag -- an int
  28.  * which is 1 for real object routines, 0 for stubs.
  29.  *
  30.  * If you call GeomKnownClassInit(), better link either with all
  31.  * object libraries or with the stub library!
  32.  *
  33.  */
  34. extern int
  35.     BBoxPresent,
  36.     BezierListPresent,
  37.     BezierPresent,
  38.     CommentPresent,
  39.     DiscGrpPresent,
  40.     InstPresent,
  41.     LincolnPresent,
  42.     ListPresent,
  43.     MeshPresent,
  44.     NDMeshPresent,
  45.     PolyListPresent,
  46.     QuadPresent,
  47.     SpherePresent,
  48.     TlistPresent,
  49.     VectPresent;
  50.  
  51. extern GeomClass *
  52.     BBoxMethods(),
  53.     BezierListMethods(),
  54.     BezierMethods(),
  55.     CommentMethods(),
  56.     DiscGrpMethods(),
  57.     InstMethods(),
  58.     LincolnMethods(),
  59.     ListMethods(),
  60.     MeshMethods(),
  61.     NDMeshMethods(),
  62.     PolyListMethods(),
  63.     QuadMethods(),
  64.     SphereMethods(),
  65.     TlistMethods(),
  66.     VectMethods();
  67.  
  68. static struct knownclass {
  69.     int *presenttag;
  70.     GeomClass *(*methods)();
  71.     char *loadsuffix;
  72. } known[] = {
  73.  
  74. #if defined(__STDC__) || defined(__ANSI_CPP__)
  75.  
  76. #define KNOWN(name, suffix) \
  77.     { &name##Present, (GeomClass *(*)())name##Methods,  suffix }
  78.  
  79. #else /* non-ANSI */
  80.  
  81. #define    KNOWN(name, suffix) \
  82.     { &name/**/Present,  (GeomClass *(*)())name/**/Methods,  suffix }
  83. #endif
  84.  
  85.     KNOWN(Bezier,    NULL),
  86.     KNOWN(BezierList,    "bez"),
  87.     KNOWN(BezierList,    "bbp"),
  88.     KNOWN(Comment,    NULL),
  89.     KNOWN(DiscGrp,    "dgp"),
  90.     KNOWN(PolyList,    "off"),
  91.     KNOWN(Sphere,    "sph"),
  92.     KNOWN(Tlist,    "tl"),
  93.     KNOWN(Tlist,    "prj"),
  94.     KNOWN(BBox,    NULL),
  95.     KNOWN(Inst,    NULL),
  96.     KNOWN(List,    "list"),
  97.     KNOWN(Quad,    "quad"),
  98.     KNOWN(Mesh,    "mesh"),
  99.     KNOWN(NDMesh,    "mesh"),
  100.     KNOWN(Vect,    "vect"),
  101.     KNOWN(Lincoln,    "iL"),
  102.     NULL
  103. };
  104.  
  105. void
  106. GeomKnownClassInit()
  107. {
  108.     register struct knownclass *k;
  109.     static char done = 0;
  110.  
  111.     if(!done) {
  112.         done = 1;
  113.         for(k = known; k->presenttag != NULL; k++)
  114.         if(*k->presenttag)
  115.             (void) (*k->methods)();
  116.     }
  117. }
  118.  
  119. /*
  120.  * This should really be in per-class attributes, not this
  121.  * centralized table, but there's no mechanism for that yet.
  122.  */
  123. GeomClass *
  124. GeomFName2Class(str)
  125.     char *str;
  126. {
  127.     register char *p;
  128.     register struct knownclass *k;
  129.  
  130.     if(str == NULL || (p = strrchr(str, '.')) == NULL)
  131.         return NULL;
  132.     p++;
  133.     for(k = known; k->presenttag != NULL; k++)
  134.         if(*k->presenttag && k->loadsuffix != NULL &&
  135.            strcmp(p, k->loadsuffix) == 0)
  136.             return((*k->methods)());
  137.     return NULL;
  138. }
  139.